package com.iflytek.yousheng;

import com.alibaba.fastjson.JSONObject;
import com.iflytek.yousheng.Util.OkHttp3Utils;
import com.iflytek.yousheng.Util.SignUtils2;

import java.io.IOException;
import java.util.UUID;

public class Audio {
    private final static String url = "https://newserver.xfyousheng.com/";
    private final static String addpath = "api/v1/tts/audio";
    private final static String appId = "xxxxxxxxx";//替换授权的appid
    private final static String appKey = "xxxxxxxxxxxxxxxxxxxxxxx";//替换对于的appkey
    private final static String vcn = "xxxxxxxxxxxxxxxxx";//替换授权的声音id
    private final static String text = "[p1000]欢迎来到科大讯飞虚拟人音频合成";

    public static void main(String[] args) {
        AddReq();
    }

    private static void AddReq() {
        String requrl = String.format("%s%s",url,addpath);
        JSONObject req = new JSONObject();

        JSONObject base = new JSONObject();
        base.put("appid", appId);
        base.put("sid", UUID.randomUUID().toString());
        base.put("timestamp", System.currentTimeMillis());



        JSONObject param = new JSONObject();
//        param.put("anchorId", anchorId);
        param.put("text", text);
        param.put("vcn",vcn);
//        param.put("spd",50);
//        param.put("rate",16);
//        param.put("vol",50);
//        param.put("format","mp3");
//        param.put("audioType",0);
//        param.put("audioUrl","http://117.71.98.4:40030/package/zxli24/video/Test.wav");

        req.put("base", base);
        req.put("param", param);

        String sign = SignUtils2.buildSign(req, appKey);
        base.put("sign", sign);


        String reqString = req.toJSONString();
        System.out.printf("请求体:%s \n", reqString);

        String respBody = "";
        try {
            respBody = OkHttp3Utils.postJson(requrl, reqString);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.printf("返回结果:%s \n", respBody);
    }

}

